//
//  MCupManager.h
//  MCupManager
//
//  Created by ylh on 15/9/15.
//  Copyright (c) 2015年 ylh. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

typedef enum
{
    DeviceNotFound = 1,                 // device is not found
    DeviceIllegal,                      // device is illegal
    DeviceUserDeny,                     // user authorization deny
    DeviceConnectFail,                  // connect fail
    DeviceServiceFoundFail,             // find service fail
    DeviceCharacteristicsFoundFail,     // find characteristics fail
    DeviceCharacteristicsEnableFail,    // enable characteristics fail
    
    Network_AppParamter_Required,       // the Appkey Or Appsercet can not be empty
    Network_App_NotFound,               // the APP not found
    Network_App_Unavailabe,             // the app authorization has been deny
    
    Bluetooth_Not_On,                   // the bluetooth is not on
} BluetoothErrorType;


@interface MCupParam : NSObject

@property(nonatomic,strong) NSString*   height;         //user height eg:180cm
@property(nonatomic,strong) NSString*   weight;         //user weight eg:60kg
@property(nonatomic,strong) NSString*   age;            //user weight eg:25
@property(nonatomic,strong) NSString*   gendor;         //user gender:1 male 2 female
@property(nonatomic,strong) NSString*   timeInterval;   //timeInterval of cup, the value is the seconds since 1970, it must be setting before first use
@property(nonatomic,strong) NSString*   timeMinutes;    //the cup current minutes in one day,if you want 08:25,you may pass (8 * 60 + 25) 505 to this value
@property(nonatomic,strong) NSString*   drinkgoal;      //drink goal eg:2000ml
@property(nonatomic,strong) NSString*   rmdmode;        //remind mode: 0(none), 1(sound only),2(shake only),3(sound+shake)
@property(nonatomic,strong) NSString*   rmdStartTime;   //startTime of the remind timezone,if you want 08:40,you may pass (8 * 60 + 40) 520 to this value
@property(nonatomic,strong) NSString*   rmdStopTime;    //stopTime if the remind timezone,if you want 22:38,you may pass (22*60 + 38) 1358 to this value
@property(nonatomic,strong)   NSString*   BatLevel;       //device battery(can not set value in parameter,just read) eg:85
@end

@interface MCupDrinkRecord : NSObject

@property(nonatomic,strong) NSString*   amount;         //amount of the drinking water
@property(nonatomic,strong) NSString*   temperature;    //temperature of the drinking water
@property(nonatomic,strong) NSString*   timeInterval;   //timeInterval of the drinking water, the value is the seconds since 1970

@end

typedef void (^CupSetBaseParamBlock)(BOOL bSuccess);
typedef void (^CupReadBaseParamBlock)(MCupParam *param);
typedef void (^CupReadDrinkRecordBlock)(NSMutableArray *dataArray);
typedef void (^CupClearDrinkRecordBlock)(BOOL bSuccess);

@protocol MCupManagerDelegate <NSObject>
@optional

/**
 The function will be called when the specify device connected success
 */
-(void)connectSuccess:(NSString *)peripheralName;

/**
 The function will be called when the specify device is connecting
 */
-(void)connecting:(NSString *)peripheralName;

/**
 The function will be called when the specify device disconnect success
 */
-(void)disconnectSuccess;

/**
 The function will be called when A new cup device have been found
 */
-(void)discoverPeripherals:(NSMutableArray *)foundPeripherals;

/**
 The function will be called when some exception error happen
 */
-(void)throwExceptionError:(BluetoothErrorType)errorDecrption;

@end


@interface MCupManager : NSObject

@property(nonatomic,assign) id<MCupManagerDelegate>   delegate;

- (id) initWithAppkey:(NSString*)appKey Sercet:(NSString*)appSercet;

/**
 Call this function to search devices:
 */
- (void)startScanning;

/**
 Call this function to stop search devices
 */
- (void) stopScanning;

/**
 Call this function to connect specify device
 */
- (void) connectPeripheral:(NSString*)peripheralName;

/**
 Call this function to disconnect the connecting device
 */
- (void) disconnectPeripheral;


/**
 Call this function to set some base parameter to the cup
 *
 *  @param params params
 *  @param block  response
 */
- (void)setCupParam:(MCupParam*)params Response:(CupSetBaseParamBlock)block;

/**
  Call this function to read parameter from the cup
 *
 *  @param block response
 */
- (void)readCupParam:(CupReadBaseParamBlock)block;

/**
 *  @param beginTimeInterval this value is the begin time you want to read,if you have read data last time
 *         you can read the time.So you can pass the last time value to this function to read the new data.
 *         if this value is 100,the Cup may give you all values.
 *   Call this function to read data of drinking
 */
- (void)readDrinkData:(NSString*)beginTimeInterval withBlock:(CupReadDrinkRecordBlock)block;

/**
 *  @param beginTimeInterval this value is the begin time you want to read,if you have read data last time
 *         you can read the time.So you can pass the last time value to this function to read the new data.
 *         if this value is 100,the Cup may give you all values.
 *   Call this function to read data of drinking
 */
- (void)clearDrinkData:(CupClearDrinkRecordBlock)block;

@end

